package cn.edu.ctbu.lddweb.service.lmpl;

import cn.edu.ctbu.lddweb.mapper.CourseMapper;
import cn.edu.ctbu.lddweb.pojo.Course;
import cn.edu.ctbu.lddweb.service.CourseService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程管理实现层
 */
@Service
public class CourseServicelmpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> selectList(Course course) {
        return courseMapper.selectList(course);
    }

    @Override
    public Course findID(@Param("id") int id) {
        return courseMapper.findID(id);
    }

    @Override
    public int insertCourse(Course course) {
        return courseMapper.insertCourse(course);
    }

    /**
     * 检查是否唯一
     * @param course
     * @return
     */
    @Override
    public Boolean checkSupplierUnique(Course course) {
        int id = course.getId()==0?-1:course.getId();
        Course info = courseMapper.checkCourseUnique(course);
        if(info!=null&&info.getId()!=id){
            return true;
        }
        return false;
    }

    @Override
    public int updateCourse(Course course) {
        return courseMapper.updateCourse(course);
    }

    @Override
    public int deleteCourse(String id) {
        return courseMapper.deleteCourse(id);
    }
}
